package us.kg.kotoriforest.servletconfig;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(
        value = "/servlet1",
        initParams = {
                @WebInitParam(name = "key1", value = "value1"),
                @WebInitParam(name = "key2", value = "value2")
        }
)
public class Servlet1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Enumeration<String> initParameterNames = getInitParameterNames();

        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        while (initParameterNames.hasMoreElements()) {
            String key = initParameterNames.nextElement();
            String value = getInitParameter(key);
            out.print(key + "=" + value + "<br/>");
        }

        out.close();
    }
}
